<template>
  <ul>
    <template v-for="item of guageList">
      <li
        v-if="item.stock > 0"
        :class="{current: item.id === guageId}"
        @click="pickGuage(item)"
        :key="item.id"
      >
        {{ item.name }}
      </li>
      <li
        v-else
        :key="item.id"
        class="no-stock"
      >
        {{ item.name }}
      </li>
    </template>
  </ul>
</template>

<script>
  export default {
    name: 'GuageList',
    props: {
      guageList: Array,
      currentGuage: String,
    },
    created() {
      if(this.currentGuage) {
        this.guageId = this.currentGuage
      } else {
        this.guageId = this.guageList.length > 1 ? '' : this.guageList[0].id
      }
    },
    data() {
      return {
        guageId: ''
      }
    },
    methods: {
      pickGuage(item) {
        this.guageId = item.id
        this.$emit('pickGuage', item)
      }
    }
  }
</script>

<style lang="scss" scoped>
  @import '@/assets/css/base.scss';
  ul {
    li {
      display: inline-block;
      margin: 0.1rem 0.2rem 0.1rem 0;
      padding: 0.1rem;
      background: $bgGray;
      border-radius: 5px;
      &.current {
        background: $colorRed;
        color: #fff;
      }
      &.no-stock {
        color: $bgGray;
        background: #fff;
      }
    }
  }
</style>
